﻿using System;
using System.Collections.Generic;


namespace Ivvy_Silverlight
{
    public class Utils
    {
        public static int ReplaceNULL = -1;

        #region "isnull"
        public static int IsNull(int? value) { if (!value.HasValue) { value = ReplaceNULL; } return (int)value; }
        public static Int64 IsNull(Int64? value) { if (!value.HasValue) { value = ReplaceNULL; } return (Int64)value; }
        public static bool IsNull(bool? value) { if (value == null) { value = false; } return (bool)value; }
        public static string IsNull(string value) { return value ?? string.Empty; }
        public static DateTime IsNull(DateTime? value) { return value ?? DateTime.MinValue; }
        #endregion

        #region "reverseisnull"        
        public static int? ReverseIsNull(int value) { if (value == ReplaceNULL) return null; else return value; }
        public static Int64? ReverseIsNull(Int64 value) { if (value == ReplaceNULL) return null; else return value; }
        public static bool? ReverseIsNull(bool value) { return value; }
        public static string ReverseIsNull(string value) { return value; }
        public static DateTime? ReverseIsNull(DateTime value) { if (value == DateTime.MinValue) return null; else return value; }
        #endregion

    }//public class Utils
}//namespace EDMD